from rest_framework import serializers
from .models import Area

class AreaSerializer(serializers.ModelSerializer):
    """省的序列化器"""
    class Meta:
        model = Area
        fields = ('id', 'name')

class SubAreaSerializer(serializers.ModelSerializer):
    """子行政区划分；详情视图使用的序列化器"""
    subs = AreaSerializer(many=True, read_only=True)
    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
        # fields = ('id', 'name', 'subs')